<template>
	<view>
		<view class="uni-title uni-common-pl">登录</view>
		<input type="text" v-model="email" placeholder="邮箱" />
		<input  type="text"  v-model="pwd" placeholder="密码" />
		<button @click="add">登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				email:'',
				pwd: ''
			}
		},
		methods: {
					
			add(){
				console.log(this.$data.email);
				console.log(this.$data.pwd)
				
				uni.request({
				    url: 'https://university-android-1.sidcloud.cn/api/auth/DebugLogin', //仅为示例，并非真实接口地址。
				    data: {
				        name: this.$data.email,
						password: this.$data.pwd
				    },
				    header: {
				        'custom-header': 'hello' //自定义请求头信息
				    },
				    success: (res) => {
						
						
						if(res.data.code!=200){
							uni.showToast({
								title:"登录错误，请检查"
							})
							
						}else{
							//console.log(res.data.data.token);
							getApp().globalData.token = res.data.data.token;
							console.log(getApp().globalData.token)
							//获取基础数据
								uni.request({
								    url: 'https://university-android-1.sidcloud.cn/api/consumer/GetInfo', //仅为示例，并非真实接口地址。
								    data: {
								    },
								    header: {
								        'Accept': 'application/json' ,
										'Authorization': 'Bearer '+getApp().globalData.token
								    },
								    success: (res) => {
										
										
										if(res.data.code!=200){
											uni.showToast({
												title:"网络错误，请检查"
											})
											
										}else{
										console.log(res.data.data)
											
										if(res.data.data=="null"){
											//new in this game
											
										}else{
											console.log(res.data.data)
											getApp().globalData.classer = res.data.data;
										}
										uni.navigateTo({
										    url: '/pages/class/class',
										})
										}
								    }
								});
						}
				    }
				});
			},
			RamColor(){
					var ram = Math.floor(Math.random() * 3 + 1);
						
					switch (ram){
					case 1:
						return "#669999"; //grey
					case 2:
						return "#ff5739";//red
					default:
						return "#9bbeff";//blue
					}
				},
		
		}
	}
</script>

<style>
.uni-picker-tips {
	font-size: 12px;
	color: #666;
	margin-bottom: 15px;
	padding: 0 15px;
	/* text-align: right; */
}
</style>
